<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #div1{
            width: 200px;
            height: 200px;
            background: #ff0000;
            position: absolute;
            bottom: 50px;
            right: 50px;
        }
        #div2{
            width: 400px;
            height: 400px;
            background: #00ff00;
            position: relative;
            top: 200px;
            left: 200px;
        }
    </style>
</head>
<body>
    <div id="div2">
        <div id="div1"></div>
    </div>

    <script>
        var oDiv = document.getElementById("div1");
//        oDiv.offsetWidth = "500px";
//        oDiv.style.width = "500px";
//        console.log(oDiv.offsetWidth);
//        console.log(oDiv.offsetHeight);
        //oDiv.style.width 只能获取内联样式的宽度 ，可以赋值
        //offsetWidth 只能取值(没有单位) 不能赋值

        console.log(oDiv.offsetTop);
        console.log(oDiv.offsetLeft);
        console.log(oDiv.offsetParent);

    </script>
</body>
</html>